package ast;

import java.io.PrintStream;
import java.util.Scanner;
import java.util.Map;
import java.util.Stack;

public class FloatConstExpr extends Expr {
    public final Double fval;

    public FloatConstExpr(Double f, Location loc) {
        super(loc);
        fval = f;
    }

    public void print(PrintStream ps) {
        ps.print(fval);
    }

    // interpret: return the value of this float constant
    public AbstractValue evaluate(Stack<Map<String, AbstractValue>> stateStack, Scanner scanner) throws Exception {
        // if fval = 0, return AbstractValue.ZeroFloat; if fval > 0, return AbstractValue.PosFloat; if fval < 0, return AbstractValue.NegFloat
        if (fval == 0) {
            return AbstractValue.ZeroFloat;
        } else if (fval > 0) {
            return AbstractValue.PosFloat;
        } else {
            return AbstractValue.NegFloat;
        }
    }
}
